*******************************************************************************
* Load candidates data
*******************************************************************************

use dataset_candidates, clear

*******************************************************************************
* Label candidates coded by others as progressive
*******************************************************************************

gen label = 0 // ADH
replace label = 1 if regex(lower(candidate), "salaz")
replace label = 1 if regex(lower(candidate), "becton")
replace label = 1 if regex(lower(candidate), "krasner")
replace label = 1 if regex(lower(candidate), "dehghani")
replace label = 1 if regex(lower(candidate), "descano")
replace label = 1 if regex(lower(candidate), "gascon")
replace label = 1 if regex(lower(candidate), "rocah")
gen labeltext = "ADH Coding" if ideology <= -.6 & ///
	regex(lower(candidate), "bec")

*******************************************************************************
* Drop if missing
*******************************************************************************

drop if mi(ideology)

*******************************************************************************
* Panel A: Graph candidate ideology against Trump vote
*******************************************************************************

cor ideology support
local myr = string(r(rho), "%20.02fc")
cor ideology support [aw=population]
local myrw = string(r(rho), "%20.02fc")

#delimit;

gr tw
	(sc ideology support if label == 0, col(black) msym(O))
	(sc ideology support if label == 1, 
		msym(O) col(gray))
	(sc ideology support if !mi(labeltext), 
		mlab(labeltext) msym(none) mlabpos(3) mlabcol(gray))
	(lfit ideology support, col(black) lwid(medthick))
 	,	
	legend(off)
	plotregion(style(none))
	xtitle("Constituency Conservatism")
	ytitle("Candidate Conservatism")
	ylab(, angle(horiz))	
	title("(a) Candidate and Voter Conservatism, Candidate-Level")
	name(g1, replace)
	text(-.95 40 "r=`myr'", col(gray))
	;
	
#delimit cr

*******************************************************************************
* Output
*******************************************************************************

gr export "_output/figureS5_a.pdf", replace

*******************************************************************************
* Panel B: Graph average candidate ideology against Trump vote by district
*******************************************************************************

preserve

	collapse ideology support population label, by(district)

	replace label = 1 if label > 0

	cor ideo support
	local myr = string(r(rho), "%20.02fc")
	cor ideo support [aw=pop]
	local myrw = string(r(rho), "%20.02fc")

	#delimit;

	gr tw
		(sc ideology support, col(black) msym(O))
		(lfit ideology support, col(black) lwid(medthick))
		,	
			plotregion(style(none))
			xtitle("Constituency Conservatism")
			ytitle("Candidate Conservatism")
			ylab(, angle(horiz))
			legend(off)
			title(
			 "(b) Candidate and Voter Conservatism, District-Level"
			)
			name(g2, replace)
			text(-.46 40 "r=`myr'", col(gray))
			;

	#delimit cr

restore

*******************************************************************************
* Output
*******************************************************************************

gr export "_output/figureS5_b.pdf", replace

*******************************************************************************
* End
*******************************************************************************
